<?php
include './logincheck.php';
nologin();
if (!empty($_POST['title']) and !empty($_POST['body']) and !empty($_POST['level'])){
    $user_id = $_SESSION['id'];
    $title = htmlspecialchars($_POST['title']);
    $body = htmlspecialchars($_POST['body']);
    $level = htmlspecialchars($_POST['level']);
    $time =date('Y-m-d H:i:s', time());
    include 'conn.php';
    $sql = "INSERT INTO article (user_id,title,body,level,time) VALUES(?,?,?,?,?);";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("issis", $user_id, $title, $body, $level, $time);
    if ($stmt->execute() === true) {
        echo "<script>alert('文章保存成功')</script>";
    }
    else{
        echo "<script>alert('文章保存失败，请联系管理员进行操作')</script>";
    }
    $stmt->close();
    die($conn->close());
}else {
    echo "<script>alert('参数数量不正确')</script>";
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文章发表界面</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 600px;
        }

        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
            color: #555;
        }

        .form-group input, .form-group textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 16px;
            box-sizing: border-box;
        }

        .form-group textarea {
            height: 200px;
            resize: vertical;
        }

        .submit-btn {
            width: 100%;
            padding: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .submit-btn:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>发表文章</h1>
    <form method="POST" action="">
        <div class="form-group">
            <label for="title">标题</label>
            <input type="text" id="title" name="title" placeholder="请输入文章标题" required>
        </div>
        <div class="form-group">
            <label for="author">权限</label>
            <input type="text" id="author" name="level" placeholder="确定权限" required>
        </div>
        <div class="form-group">
            <label for="content">内容</label>
            <textarea id="content" name="body" placeholder="请输入文章内容" required></textarea>
        </div>
        <button type="submit" class="submit-btn">提交</button>
    </form>
</div>
</body>
</html>
